#include "Timer.h"

CTimer::CTimer()
{
	LastTick = 0;
	Fraq = 0;
	fFPS = 0.0f;
	fDT = 0.0f;
}

CTimer::~CTimer()
{
	Free();
}

bool CTimer::Init()
{
	if( !QueryPerformanceFrequency( (LARGE_INTEGER*)&Fraq ) )
	{
		Fraq = 0;
		return false;
	}

	QueryPerformanceCounter( (LARGE_INTEGER*)&LastTick );
	return true;
}

void CTimer::Update()
{
	if( Fraq == 0 )
		return;

	__int64 ThisTick = 0;
	QueryPerformanceCounter( (LARGE_INTEGER*)&ThisTick );

	fDT = float( double(ThisTick - LastTick) / double(Fraq) );
	LastTick = ThisTick;

	if( fDT != 0.0f )
		fFPS = 1.0f / fDT;
}

void CTimer::Free()
{
	LastTick = 0;
	Fraq = 0;
	fFPS = 0.0f;
	fDT = 0.0f;
}

float CTimer::GetDT()
{
	return fDT;
}

float CTimer::GetFPS()
{
	return fFPS;
}